from pynput import keyboard
from pynput import mouse
import time

skip = False

is_pressed0 = False
is_pressed = False
is_pressed2 = False
press_co = 0
press_state = False
insert_co = 0
is_working = True
alt_pressed = False
shift_pressed = False
ctrl_pressed = False
import random
tt = time.time()
is_p = False
is_w = True

def on_press(key):
    global tt
    print('pre', str(key))
    global is_p, is_w
    if  'Key.left' == str(key):
        is_p = True
    if is_p and  'Key.right' == str(key):
        is_w = not is_w
        print('is_w', is_w)
    if time.time() - tt < 0.2:
        return
    if not is_w:
        return
    
    if 'Key.down' == str(key) or 'Key.up' == str(key):
        tt = time.time()
        if 'Key.down' == str(key):
            keyboard.Controller().press(keyboard.Key.up)
            keyboard.Controller().release(keyboard.Key.up)
        else:
            keyboard.Controller().press(keyboard.Key.down)
            keyboard.Controller().release(keyboard.Key.down)
                    
        
        if 'Key.down' == str(key):
            i = random.randint(1, 9)
        else:
            i = random.randint(2, 10)
            
        j = random.randint(2, 3)
        print(i, j)
        if i % 2 == 0:
            for ii in range(0, j):
                keyboard.Controller().press(keyboard.Key.page_up)
                keyboard.Controller().release(keyboard.Key.page_up)
        else:
            for ii in range(0, j):
                keyboard.Controller().press(keyboard.Key.page_down)
                keyboard.Controller().release(keyboard.Key.page_down)
        
    
def on_release(key):
    global is_p
    if  'Key.left' == str(key):
        is_p = False
        
    return
  
listener = keyboard.Listener(
    on_release=on_release,
    on_press=on_press,
    
)
listener.start()
import time
while True:
    time.sleep(100)